#include <iostream>

using namespace std;


void PrintUseBitField()
{
		struct kingpos
		{
				unsigned char a : 4;
				unsigned char b : 4;
		}s;

		for(s.a = 1; s.a <= 9; ++s.a)
		{
				for(s.b = 1; s.b <= 9; ++s.b)
				{
						if(s.a % 3 != s.b % 3)
								// you must convert it to int here, or else it will call the "char" version of operator <<, which will result in output ascii char between 0-15
								cout << "(" << (int)s.a << "," << (int)s.b << ")" << endl; 
				}
		}
}

#define LMASK 0xF0
#define RMASK 0x0F
#define LGET(b) ((b & LMASK) >> 4)
#define RGET(b) (b & RMASK)
#define LSET(b, v) b = ((b & RMASK) | v << 4) // you need to set it back to the original byte, if you really want SET!!!
#define RSET(b, v) b = ((b & LMASK) | v)

void PrintUseBitOperation()
{
	unsigned char b = 0;

	for(LSET(b, 1); LGET(b) <= 9; LSET(b, LGET(b)+1))
		for(RSET(b, 1); RGET(b) <= 9; RSET(b, RGET(b)+1))
		{
			if(LGET(b) % 3 != RGET(b) % 3)
				cout << "(" << (int)LGET(b) << "," << (int)RGET(b) << ")" << endl; 
		}	

}

int main(int argc, const char* argv[])
{
// 		PrintUseBitField();
		PrintUseBitOperation();
		return 0;
}
